// CompanyAuditController.java
package com.lingnan.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lingnan.dto.CompanyAuditDTO;
import com.lingnan.dto.CompanyAuditRequest;
import com.lingnan.dto.CompanyQueryRequest;
import com.lingnan.entity.vo.Result;
import com.lingnan.service.CompanyAuditService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/company")
@RequiredArgsConstructor
public class CompanyAuditController {
    
    private final CompanyAuditService companyAuditService;
    
    /**
     * 分页查询企业审核列表
     */
    @GetMapping("/audit/list")
    public Result<IPage<CompanyAuditDTO>> getCompanyAuditList(CompanyQueryRequest query) {
        return companyAuditService.getCompanyAuditList(query);
    }
    
    /**
     * 获取企业详细信息
     */
    @GetMapping("/detail/{companyId}")
    public Result<CompanyAuditDTO> getCompanyDetail(@PathVariable("companyId") Long companyId) {
        return companyAuditService.getCompanyDetail(companyId);
    }
    
    /**
     * 审核企业资质
     */
    @PostMapping("/audit")
    public Result<Void> auditCompany(@Valid @RequestBody CompanyAuditRequest request,
                                   @RequestParam("adminId") Long adminId) {
        return companyAuditService.auditCompany(request, adminId);
    }
    
    /**
     * 批量审核企业资质
     */
    //ZSH TODO 2025/7/30没有实现批量发送通信
    @PostMapping("/audit/batch")
    public Result<Void> batchAuditCompany(@RequestBody @Valid CompanyAuditRequest[] requests,
                                        @RequestHeader("adminId") Long adminId) {
        try {
            for (CompanyAuditRequest request : requests) {
                Result<Void> result = companyAuditService.auditCompany(request, adminId);
                if (!result.isSuccess()) {
                    return Result.fail("批量审核失败：" + result.getMessage());
                }
            }
            return Result.ok();
        } catch (Exception e) {
            return Result.fail("批量审核失败");
        }
    }
}